<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
  <description>
   Bean configuration file for the gwc-core module
  </description>

  <bean id="geoWebCacheExtensions" class="org.geowebcache.GeoWebCacheExtensions"/>
  
  <bean id="geoWebCacheEnvironment" class="org.geowebcache.GeoWebCacheEnvironment" depends-on="geoWebCacheExtensions"/>
  
  <bean id="gwcAppCtx" class="org.geowebcache.util.ApplicationContextProvider" />
  
  <bean id="gwcXmlConfigResourceProvider" class="org.geoserver.gwc.config.GeoserverXMLResourceProvider">
     <constructor-arg value="geowebcache.xml" />
     <constructor-arg ref="resourceStore" />
  </bean>
  
  <!-- The location of a static configuration file for GeoWebCache. 
       By default this lives in WEB-INF/classes/geowebcache.xml -->
  <bean id="gwcXmlConfig" class="org.geowebcache.config.XMLConfiguration">
    <constructor-arg ref="gwcAppCtx" />
    <constructor-arg ref="gwcXmlConfigResourceProvider" />
    <property name="template" value="/geowebcache_empty.xml">
      <description>Create an empty geoebcache.xml in data_dir/gwc as template</description>
    </property>
  </bean>
  
  <!-- If you like to automatically configure GWC from a WMS Getcapabilities document,
       change the values below. The last constructor-arg lets you specify parameters 
       that are appended to every WMS request to the backed, for example: 
       "format_options=regionate_by:auto&amp;bgcolor=0x112233" 
       
       You also need to uncomment gwcWMSConfig in the gwcTLDispatcher bean!
       -->
  <!--bean id="gwcWMSConfig" class="org.geowebcache.config.wms.GetCapabilitiesConfiguration">
  	<constructor-arg ref="gwcGridSetBroker">
    </constructor-arg>
    <constructor-arg value="http://demo.mapserver.org/cgi-bin/mapserv?map=/osgeo/mapserver/msautotest/world/world.map&amp;SERVICE=WMS&amp;VERSION=1.1.1&amp;REQUEST=GetCapabilities">
      <description>The URL to the WMS GetCapabilities document, notice &amp; , port is normally 8080</description>
    </constructor-arg>
    <constructor-arg value="image/png">
      <description>The formats to support for all layers read for the above document</description>
    </constructor-arg>
    <constructor-arg value="3x3">
      <description>Metatiling factors, 3x3 is usually a good compromise for vector data</description>
    </constructor-arg>
    <constructor-arg value="map=/osgeo/mapserver/msautotest/world/world.map">
      <description>
          Vendor parameters, these are appended to every request sent to the backend.
          If you use MapServer you probably want to set this to "map=name". Leave the value attribute empty if you don't need
          to add any vendor specific parameter.
      </description>
    </constructor-arg>
    <constructor-arg value="false">
      <description>Whether to allow cached=false to specificed for certain requests</description>
    </constructor-arg> 
  </bean-->

  <bean id="gwcSecurityDispatcherTileLayerDispatcherFilter" class="org.geowebcache.layer.SecurityDispatcherTileLayerDispatcherFilter">
    <constructor-arg ref="gwcSecurityDispatcher"/>
  </bean>
  
  <!-- For each configuration bean above, add them below to activate -->
  <bean id="gwcTLDispatcher" class="org.geowebcache.layer.TileLayerDispatcher" depends-on="gwcCatalogConfiguration,geoWebCacheExtensions">
    <description>
      TileLayerDispatcher serves up TileLayers from the available Configurations in the application context
    </description>
    <constructor-arg ref="gwcGridSetBroker"/>
    <constructor-arg ref="gwcSecurityDispatcherTileLayerDispatcherFilter"/>
  </bean>

  <bean id="gwcBlobStoreAggregator" class="org.geowebcache.storage.BlobStoreAggregator">
    <description>
      BlobStoreAggregator serves up BlobStoreInfos from the available Configurations in the application context
    </description>
  </bean>
  
  <bean id="gwcDefaultStorageFinder" class="org.geowebcache.storage.DefaultStorageFinder">
  	<constructor-arg ref="gwcAppCtx" />
  </bean>

  <bean id="gwcBlobStore" class="org.geowebcache.storage.CompositeBlobStore" destroy-method="destroy">
    <constructor-arg ref="gwcTLDispatcher"/>
    <constructor-arg ref="gwcDefaultStorageFinder" />
    <constructor-arg ref="gwcBlobStoreAggregator"/>
    <constructor-arg ref="gwcXmlConfig"/>
  </bean>
  
  <!-- Static definition of where to put the blobstore. 
       Note that the directory MUST EXIST when GWC is started. -->
  <!-- bean id="gwcBlobStore" class="org.geowebcache.storage.blobstore.file.FileBlobStore" destroy-method="destroy">
    <constructor-arg value="/tmp/gwc_blobstore" />
  </bean -->
  
  <bean id="gwcStorageBroker" class="org.geowebcache.storage.DefaultStorageBroker" destroy-method="destroy">
    <constructor-arg ref="gwcConfigBlobStore" />
    <constructor-arg>
      <bean class="org.geowebcache.storage.TransientCache">
        <constructor-arg index="0" value="100"/>
        <constructor-arg index="1" value="1024"/>
        <constructor-arg index="2" value="2000"/>
      </bean>
    </constructor-arg>
  </bean>
  
  
  <bean id="gwcGridSetBroker" class="org.geowebcache.grid.GridSetBroker">
    <constructor-arg>
      <list>
        <bean id="defaultGridsets" class="org.geowebcache.config.DefaultGridsets">
          <!-- Should we used EPSG:900913 instead of EPSG:3857 ? -->
          <constructor-arg type="boolean" value="TRUE" />
          <!--
            Should the default grids be named EPSG:4326 and EPSG:900913 (TRUE),
            or (FALSE) use the new names similar to what WMTS suggests,
            GlobalCRS84Geometric and GoogleMapsCompatible ? 
            
            If you say FALSE here, you have to manually
            rename the directories and entries in the H2 database.
           -->
          <constructor-arg type="boolean" value="TRUE" />
        </bean>
      </list>
    </constructor-arg>
  </bean>
  
  <bean id="gwcRuntimeStats" class="org.geowebcache.stats.RuntimeStats" destroy-method="destroy">
    <!-- The poll interval, the number of seconds until counters are aggregated -->
    <constructor-arg type="int" value="3" />
    <!-- The intervals (in seconds) for which aggregates are reported.
         Each interval must be a multiple of the poll interval above and
         listed in ascending order. For example, for a maximum interval 
         of 60 seconds and 3 second poll interval from above, the amount
         of memory consumed is (60 / 3) * 8 = 160 bytes
    -->
    <constructor-arg>
      <list>
        <value>3</value>
        <value>15</value>
        <value>60</value>
      </list>
    </constructor-arg>
    <!-- Descriptive texts for each of the intervals above -->
    <constructor-arg>
      <list>
        <value>3 seconds</value>
        <value>15 seconds</value>
        <value>60 seconds</value>
      </list>
    </constructor-arg>
  </bean>
  
  <!-- controller for handling all incoming requests -->
  <bean id="geowebcacheDispatcher" class="org.geowebcache.GeoWebCacheDispatcher" destroy-method="destroy">
    <constructor-arg ref="gwcTLDispatcher"/>
    <constructor-arg ref="gwcGridSetBroker"/>
    <constructor-arg ref="gwcStorageBroker"/>
    <constructor-arg ref="gwcBlobStoreAggregator"/>
    <constructor-arg ref="gwcXmlConfig"/>
    <constructor-arg ref="gwcRuntimeStats"/>
    <property name="defaultStorageFinder" ref="gwcDefaultStorageFinder"/>
    <property name="securityDispatcher" ref="gwcSecurityDispatcher"/>
    <property name="servletPrefix" value="gwc"/>
  </bean>
	
  <!-- Thread pool for seeding -->
  <bean id="gwcSeederThreadPoolExec" 
    class="org.geoserver.gwc.seed.SeederThreadLocalTransferExecutor">
    <constructor-arg value="16"/><!-- Size of core pool -->
    <constructor-arg value="32"/><!-- Maximum size of pool -->
  </bean>

  <!-- Breeder (the one that seeds) -->
  <bean id="gwcTileBreeder" class="org.geowebcache.seed.TileBreeder">
    <property name="tileLayerDispatcher" ref="gwcTLDispatcher"/>
    <property name="threadPoolExecutor" ref="gwcSeederThreadPoolExec"/>
    <property name="storageBroker" ref="gwcStorageBroker"/>
  </bean>

  <bean id="gwcProxyDispatcher"
	class="org.geowebcache.proxy.ProxyDispatcher"/>
  
  <!-- Lock providers -->
  <bean id="noLock" class="org.geowebcache.locks.NoOpLockProvider"/>

  <bean id="gwcURLMangler" class="org.geoserver.gwc.ResponseUtilsURLMangler" />

  <bean id="gwcSecurityDispatcher" class="org.geowebcache.filter.security.SecurityDispatcher" />

  <bean id="memoryLock" class="org.geowebcache.locks.MemoryLockProvider"/>
  
  <bean id="nioLock" class="org.geowebcache.locks.NIOLockProvider">
    <constructor-arg ref="gwcDefaultStorageFinder"/>
  </bean>
  
  <bean id="globalLock" class="org.geoserver.gwc.GeoServerLockProvider">
      <property name="delegate" ref="lockProvider"/>
  </bean>
  
  <!-- The tool performing the automatic migration between metastore and fs hashes -->
  <bean id="metastoreRemover" class="org.geowebcache.storage.MetastoreRemover">
    <constructor-arg ref="gwcDefaultStorageFinder"/>
  </bean>
  
  <bean id="cacheConfiguration" class="org.geowebcache.storage.blobstore.memory.CacheConfiguration">
    <property name="hardMemoryLimit" value="64"/> <!-- 64 Mb -->
    <property name="policy" value="EXPIRE_AFTER_ACCESS"/> <!-- 64 Mb -->
  </bean>
  
   <bean id="guavaCacheProvider" class="org.geowebcache.storage.blobstore.memory.guava.GuavaCacheProvider">
     <constructor-arg ref="cacheConfiguration"/>
  </bean>
  
    <bean id="gwcMemoryBlobStore" class="org.geowebcache.storage.blobstore.memory.MemoryBlobStore" destroy-method="destroy">
    <property name="store" ref="gwcBlobStore" />
    <property name="cacheProvider" ref="guavaCacheProvider" />
  </bean>
  
 <bean id="gwcNullBlobStore" class="org.geowebcache.storage.blobstore.memory.NullBlobStore" destroy-method="destroy"/>
 
  <bean id="gwcConfigBlobStore" class="org.geoserver.gwc.ConfigurableBlobStore" destroy-method="destroy">
      <constructor-arg ref="gwcBlobStore" />
      <constructor-arg ref="gwcMemoryBlobStore" />
      <constructor-arg ref="gwcNullBlobStore" />
  </bean>

</beans>
